package com.ceba.test.modules.admin.helper;

import java.util.List;

import com.ceba.base.helper.LoggerHelper;
import com.ceba.cebautils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ceba.test.modules.admin.entity.CustomResource;
import com.ceba.test.modules.admin.entity.FTPObject;
import com.ceba.test.modules.admin.entity.GStamp;
import com.ceba.test.modules.admin.entity.ISign;
import com.ceba.test.modules.admin.logicService.AdminLogicService;

import configs.context.SpringBeans;



public class ISignHelper {
	static Logger logger = LoggerFactory.getLogger(ISignHelper.class);
	
	private static AdminLogicService adminLogicService = SpringBeans.getAdminLogicService("adminLogicService");
	public static ISign getInterfaceSignById(String id){
		ISign iSign = null;
		String stampNameHtml=" ";
		String stampPath = " ";
		try{
			iSign = adminLogicService.getInterfaceSignById(id);	
			List<GStamp> stampList = adminLogicService.getMultiInterfaceSigns();
			if(stampList !=null &&stampList.size()>0){
				stampNameHtml="";
				for (GStamp row : stampList) {
					if(!StringUtil.isEmptyString(row.getName())){
						if(row.getId().equals(iSign.getStampID())){
							stampNameHtml+="<option value=\""+row.getId()+"\"  selected>"+row.getName()+"</option>";
						}else{
							stampNameHtml+="<option value=\""+row.getId()+"\">"+row.getName()+"</option>";
						}
					}
				}
			}
			iSign.setStampNameHtml(stampNameHtml);
			iSign.setQfRuleHtml(getQfRule(iSign.getQfRuleId()));
//			iSign.setCredentialsHtml(getCredentials(iSign.getCredentialsId()));
			
			GStamp gs = adminLogicService.getCorStampObjectByStampId(iSign.getStampID());
			if(gs !=null){
				stampPath = gs.getFilePath();
			}
			iSign.setStampPath(stampPath);
		} catch (Exception e) {
			LoggerHelper.error(logger, e, "");
		}
		return iSign;
	}
	
	public static ISign getMultiInterfaceSigns(){
		ISign iSign = new ISign();
		String stampNameHtml = "";
		try {
			List<GStamp> stampList =  adminLogicService.getMultiInterfaceSigns();
			if(stampList!=null && stampList.size()>0){
				for (GStamp row : stampList) {
					if(!StringUtil.isEmptyString(row.getName())){
						stampNameHtml+="<option value=\""+row.getId()+"\">"+row.getName()+"</option>";
					}
				}
			}
			iSign.setStampNameHtml(stampNameHtml);
			iSign.setQfRuleHtml(getQfRule(""));
//			iSign.setCredentialsHtml(getCredentials(""));
		} catch (Exception e) {
			LoggerHelper.error(logger, e, "");
		}
		return iSign;
	}
	

	
	//获取骑缝章规则
	public static String getQfRule(String qrRuleId){
		String qfRuleHtml = "";
		String  qfRuleId="";
		//获取骑缝章规则记录
		CustomResource cr=CustomResourceHelper.getByIdCusResouse(qrRuleId);
	      if(cr!=null){
	    	  qfRuleId=cr.getId();
	      }
		try {
			List<CustomResource> list=adminLogicService.getQfRule();
			if(list !=null &&list.size()>0){
				for (CustomResource row : list) {
					if(!StringUtil.isEmptyString(row.getCusfaceName())){
						if(row.getId().equals(qfRuleId)){
							qfRuleHtml+="<option value=\""+row.getId()+"\"  selected>"+row.getCusfaceName()+"</option>";
						}else{
							qfRuleHtml+="<option value=\""+row.getId()+"\">"+row.getCusfaceName()+"</option>";
						}
					}
				}
			}
			
		} catch (Exception e) {
			LoggerHelper.error(logger, e, "");
		}
		return qfRuleHtml;
	}

	
	public static FTPObject getFTPSettingById(String id){
		FTPObject ftpSetting = adminLogicService.getFTPObjectById(id);		
		return ftpSetting;
	}
}
